<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="Connect.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
<title>Hammer Time Auctions</title>
<script language="javascript" type="text/javascript">
	function registerClicked() {
		javascript: update.submit();
	}
</script>
</head>
<body>
	<div id="content">
		<%@include file="header.jsp"%>
		<h1>Edit Profile</h1>
		<hr></hr>
		<%
			String username = (String) session.getAttribute("logged_user");
			// Connect to the database.
			Class.forName(ConnectionInfo.myJDBCDriver()).newInstance();
			java.util.Properties sysprops = System.getProperties();
			sysprops.put("user", ConnectionInfo.myUserID());
			sysprops.put("password", ConnectionInfo.myPassword());
			java.sql.Connection conn = java.sql.DriverManager.getConnection(ConnectionInfo.myURL(), sysprops);
			java.sql.ResultSet rs = null;
			// Display a table of employee information.
			java.sql.Statement statement = conn.createStatement();
			if (session.getAttribute("user_type").equals("1") || session.getAttribute("user_type").equals("0")) {
				rs = statement.executeQuery("SELECT users.*, employees.start_date, employees.hourly_wage, employees.level, employees.ssn "
						+ "FROM users Right Join employees ON users.username = employees.username " + "WHERE users.username='" + username + "'");
			}
			if (session.getAttribute("user_type").equals("2")) {
				rs = statement.executeQuery("SELECT users.*, customers.credit_card_number "
						+ "FROM users RIGHT JOIN customers ON users.username = customers.username WHERE users.username='" + username + "'");
			}
			rs.next();
			// Display the list of registration errors if there are any.
			if (session.getAttribute("register_errors") != null) {
				out.println("<div class=\"section padding-5px error-text\">");
				out.println(session.getAttribute("register_errors"));
				out.println("</div>");
			}
		%>
		<div class="center">
			<form name="update" action="edit_profile_validate.jsp" method="post">
				<table class="center">
					<tr>
						<td><label class="form-label" for="username">Username:</label></td>
						<td><%=rs.getString(1)%><input type="hidden" value="<%=rs.getString(1) %>" name="username"/></td>
					</tr>
					<tr>
						<td><label class="form-label" for="password">Password:</label></td>
						<td><input name="password" type="password" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="retype_password">Retype Password:</label></td>
						<td><input name="retype_password" type="password" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="email">Email:</label></td>
						<td><input name="email" type="text" value="<%=rs.getString(3)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="first_name">First Name:</label></td>
						<td><input name="first_name" type="text" value="<%=rs.getString(4)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="last_name">Last Name:</label></td>
						<td><input name="last_name" type="text" value="<%=rs.getString(5)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="address">Address:</label></td>
						<td><input name="address" type="text" value="<%=rs.getString(6)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="city">City:</label></td>
						<td><input name="city" type="text" value="<%=rs.getString(7)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="state">State:</label></td>
						<td><input name="state" type="text" value="<%=rs.getString(8)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="zip_code">ZIP Code:</label></td>
						<td><input name="zip_code" type="text" value="<%=rs.getString(9)%>" /></td>
					</tr>
					<tr>
						<td><label class="form-label" for="telephone">Telephone:</label></td>
						<td><input name="telephone" type="text" value="<%=rs.getString(10)%>" /></td>
					</tr>
					<%
						if (session.getAttribute("user_type").equals("2")) {
							out.println("<tr>");
							out.println("<td><label class=form-label for=credit_card_number>Credit	Card Number:</label></td>");
							out.println("<td><input name=credit_card_number type=text value=");
					%><%=rs.getString(11)%>
					<%
						out.println("></td></tr>");
						}
					%>
					<tr>
					<tr>
						<%
							if (session.getAttribute("user_type").equals("1") || session.getAttribute("user_type").equals("0")) {
								out.println("<tr>");
								out.println("<td><label class=form-label>Start Date</label></td>");
								out.println("<td><input name=start_date type=text value=");
						%><%=rs.getString(11)%>
						<%
							out.println(" Readonly></td></tr>");
							}
						%>
					</tr>
					<tr>
						<%
							if (session.getAttribute("user_type").equals("1")) {
								out.println("<tr>");
								out.println("<td><label class=form-label>Hourly Wage</label></td>");
								out.println("<td><input name=hourly_wage type=text value=");
						%><%=rs.getString(12)%>
						<%
							out.println(" Readonly></td></tr>");
							} else {
								if (session.getAttribute("user_type").equals("0")) {
									out.println("<tr>");
									out.println("<td><label class=form-label>Hourly Wage</label></td>");
									out.println("<td><input name=hourly_wage type=text value=");
						%><%=rs.getString(12)%>
						<%
							out.println(" ></td></tr>");
								}
							}
						%>
					</tr>
					<tr>
						<%
							out.println("<tr>");
							out.println("<td><label class=form-label>Level</label></td>");
							out.println("<td>" + rs.getString(13)+ "</td>");
							out.println("<td><input name=level type=hidden value='" + rs.getString(13)+"'></td>");						  	
							out.println("</tr>");						
							out.println(" </td></tr>");							
						%>
					</tr>
					<tr>
						<%
							if (session.getAttribute("user_type").equals("1") || session.getAttribute("user_type").equals("0")) {
								out.println("<tr>");
								out.println("<td><label class=form-label>Social Security</label></td>");
								out.println("<td><input name=ssn type=text value=");
						%><%=rs.getString(14)%>
						<%
							out.println(" ></td></tr>");
							}
						%>
					</tr>
					<tr>
						<td></td>
						<td><a href="#" class="right button" type="submit" onclick="return registerClicked()">Update</a></td>
					</tr>
				</table>
				<input type="submit" class="hidden" />
			</form>
		</div>
		<%
			//Clear the Errors after read
			session.setAttribute("register_errors", null);
			statement.close();
			conn.close();
		%>
		<%@include file="footer.jsp"%>
	</div>
</body>
</html>